# include <bits/stdc++.h>
# define N 305
using namespace std;
int n,a[N];
int f[N][N][N];
void ckmin(int &x,int y)
{
    x=min(x,y);
}
int main()
{
    freopen("build.in","r",stdin);
    freopen("build.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    memset(f,0x3f,sizeof f);
    for(int i=1;i<=n;i++)
    {
        f[1][i][a[i]]=0;
        for(int j=1;j<=n;j++)
            if(j!=a[i])
                f[1][i][j]=1;
    }
    for(int len=1;len<n;len++)
        for(int i=1;i<=n-len+1;i++)
            for(int j=1;j<=n-len+1;j++)
            {
                int now=f[len][i][j];
                ckmin(f[len+1][i-1][j-1],now+(a[i-1]!=j-1));
                ckmin(f[len+1][i][j-1],now+(a[i+len]!=j-1));
                ckmin(f[len+1][i-1][j],now+(a[i-1]!=j+len));
                ckmin(f[len+1][i][j],now+(a[i+len]!=j+len));
            }
    cout<<f[n][1][1]<<endl;
    return 0;
}